"""Meaningless comments"""

from entity import*
from trigger import*
import math

class camera(entity):
    """A camera to look around"""
    def __init__(self,manager,  screenWidth, screenHeight):
        entity.__init__(self, manager)
        self.focus = 0
        self.rect.width = screenWidth
        self.rect.height = screenHeight
        self.updates = True
        self.edit = False

        self.scrollspeed = 40 #THIS IS SCROLLSPEED. Higher numbers == slower!
        self.movecam = 0
        
		
    def setFocus(self, entity):
        self.focus = entity
        self.basex = self.focus.rect.x + (self.rect.width / 2)
        self.basey = self.focus.rect.y
        self.pastx = self.focus.rect.x
        self.currentx = self.pastx
        
        self.mx = 0
        self.my = 0
    
    def newFocus(self, entity):
        self.focus = entity
        
    def seteditmode(self,edit):
        self.edit = edit
        
        
    
    def getevents(self,events):
        self.events = events
        
    def followFocus(self): 
        if (self.edit != True):
            self.mx = 0
            self.my = 0
        
            self.currentx = self.focus.rect.x
            if self.currentx > self.pastx + 30:
                self.movecam = 2
                self.pastx = self.currentx            
            elif self.currentx < self.pastx - 30:
                self.movecam = 1
                self.pastx = self.currentx            

             
            if self.movecam == 2:
                camera.goto(self,self.focus.rect.x + 100,self.focus.rect.y)
            elif self.movecam == 1:
                camera.goto(self,self.focus.rect.x - 100,self.focus.rect.y)
            elif self.movecam == 3:
                camera.goto(self,self.focus.rect.x,self.focus.rect.y)
        else:
            if pygame.mouse.get_pressed()[2]:
                if pygame.mouse.get_pos()[0] < 75:
                    self.mx = self.mx - 5
                if pygame.mouse.get_pos()[1] < 75:
                    self.my = self.my - 5
                if pygame.mouse.get_pos()[0] > self.rect.width - 75:
                    self.mx = self.mx + 5
                if pygame.mouse.get_pos()[1] > self.rect.height - 75:
                    self.my = self.my + 5

                camera.goto(self, pygame.mouse.get_pos()[0] + self.mx,pygame.mouse.get_pos()[1] + self.my)
                
    def goto(self,x,y):
        stepx = 0
        stepy = 0
        
        stepx = (x - self.basex) / self.scrollspeed
        stepy = (y - self.basey) / (self.scrollspeed / 1.5) 
            
            
        if math.fabs(y) > math.fabs(x):
            stepy = stepy / 2
        if math.fabs(x) > math.fabs(y):
            stepy = stepy / 2
        self.basex = self.basex + stepx
        self.basey = self.basey + stepy
        
        self.moveTo(self.basex -  (self.rect.width /2),self.basey - (self.rect.height /2))
            
                
            
    def update(self, timeelapsed, manager):
        self.followFocus()

